//*****************************************************************************
//
//! \addtogroup Intro_c
//! @{
//
//*****************************************************************************

#include "intro.h"
#include "hw_memmap.h"
#include "hw_types.h"
#include "hw_ints.h"
#include "sysctl.h"
#include "osram96x16x1.h"

unsigned long delayTime; ///< Use for program delay

//*****************************************************************************
//
//! Scroll intro text on the display.
//!
//!	Shows information about project name and authors scrolling on the display
//!
//! \return None
//
//*****************************************************************************
void intro(void)
{
	
	unsigned long i, j;	

	// Strings to be displayed
	char line1Prj[] = " JCI Project 8  Arkanoid";
	char line2Names[]=" Copyright MSS, NSN, VSK";

	// Variables used to move the text
	char *line1StrPos = line1Prj;
	char *line2StrPos = line2Names;
	unsigned char cnt = 0;

	delayTime = SysCtlClockGet()/25;

	// Show strings
	OSRAM96x16x1Clear();
	OSRAM96x16x1StringDraw(line1StrPos, 0, 0);
	OSRAM96x16x1StringDraw(line2StrPos, 0, 1);

	// Delay for some time
	for (j = 0; j < 4*delayTime; ++j);

	// Scrolls text twice from left to right and vice versa
 	for(i = 0; i < 2; ++i)
	{
		// Moves text lines from left to right
		while (++cnt<9)
		{
			++line1StrPos;
			++line2StrPos;
			
			OSRAM96x16x1StringDraw(line1StrPos, 0, 0);
			OSRAM96x16x1StringDraw(line2StrPos, 0, 1);
			for (j = 0; j < delayTime; ++j);
		}

		// Delay
		for (j = 0; j < 3*delayTime; ++j);

		// Moves text lines from right to left
	   	while (cnt--)
		{
			line1StrPos = line1Prj;
	    	line2StrPos = line2Names;
			line1StrPos += cnt;
			line2StrPos += cnt;
		   	OSRAM96x16x1StringDraw(line1StrPos, 0, 0);
			OSRAM96x16x1StringDraw(line2StrPos, 0, 1);

			// Delay
			for (j = 0; j < delayTime; ++j);
		}			 
		++cnt;
	   for (j = 0; j < 4*delayTime; ++j);	   
	}
	OSRAM96x16x1Clear();			  
}


//*****************************************************************************
//
//! Await button activity to start game.
//!
//!	Shows blinking text "Press button to start game" until the button is
//! pressed then initializes variable for time measuring with 0. After that
//! program execution continues with game.
//!
//! \return None
//
//*****************************************************************************
void waitBtnPush(void)
{
	extern unsigned long secPlayed;
	extern unsigned char btnFlag;
	unsigned long j;
	delayTime = SysCtlClockGet()/25;	
	
	// Clears btnFlag for eliminating button interrupts while showing intro
	btnFlag = 0;

	// Waiting for button action while displaying message
	while (!btnFlag)
	{
		OSRAM96x16x1StringDraw("Press button", 12, 0);
		OSRAM96x16x1StringDraw("to start game!", 6, 1);
		for (j = 0; (j < delayTime) && (!btnFlag); ++j);
		OSRAM96x16x1Clear();
		for (j = 0; (j < delayTime) && (!btnFlag); ++j);
	}

	
	// Initialization of variables after button click
	secPlayed = 0;
}		 

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
